package com.itheima.service.impl;

import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.StuOption;
import com.itheima.service.StuReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StuReportServiceImpl implements StuReportService {
    @Autowired
    private StudentMapper studentMapper;

    /**
     *  统计班级学生人数
     * @return
     */
    @Override
    public StuOption getStudentCountData() {
        List<Map<String, Object>> list = studentMapper.countStudentData();
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new StuOption(clazzList, dataList);
    }

    /**
     * 统计各学历人数
     * @return
     */
    @Override
    public List<Map> getStuDegreeData() {
        return studentMapper.countStuDegreeData();
    }
}
